package com.jr.dao.impl;

import com.jr.dao.IUserDao;
import com.jr.pojo.User;
import com.jr.util.DBHelper;

import java.util.ArrayList;

public class UserDaoImpl implements IUserDao {
    DBHelper db = new DBHelper();
    //注册
    @Override
    public int insertUser(User u) {
        StringBuilder sb = new StringBuilder("insert into users values(null,?,?,?,?,?,?)");
        Object[]obj={u.getUsercode(),u.getPassword(),u.getEmail(),u.getGender(),u.getRegistertime(),u.getLastlogintime()};

        return db.dtUpdate(sb.toString(),obj);
    }

    //登录
    @Override
    public User selectUserByUser(User u) {
        StringBuilder sb = new StringBuilder("select * from users where usercode=? and password=?");
        Object[]obj={u.getUsercode(),u.getPassword()};
        ArrayList<User> list = (ArrayList<User>)(db.dtQuery(sb.toString(), User.class, obj));
        User user = list.get(0);
        return user;
    }
}
